#include <gflags/gflags.h>
#include "../../../Common/mysql_user.hpp"
//日志类参数
DEFINE_bool(log_mod,false,"true为发布模式,false为调试模式");
DEFINE_string(log_file,"","发布模式下日志存储的文件");
DEFINE_int32(log_level,0,"要输出的日志等级");
void insert(zzy_mims::UserTable& ut)
{
    auto user1=std::make_shared<zzy_mims::User>("uid1","zzy","616161");
    auto user2=std::make_shared<zzy_mims::User>("uid2","17373xxxxxx");
    if(!ut.insert(user1))
    std::cout<<"insert user1 err\n";
    if(!ut.insert(user2))
    std::cout<<"insert user2 err\n";
}
void update_by_id(zzy_mims::UserTable& ut)
{
    auto user = ut.select_by_id("uid2");
    user->description("O(∩_∩)O v1");
    ut.update(user);
}
void update_by_phone(zzy_mims::UserTable& ut)
{
    auto user = ut.select_by_phone("17373xxxxxx");
    user->description("O(∩_∩)O v2");
    ut.update(user);
}
void update_by_nickname(zzy_mims::UserTable& ut)
{
    auto user = ut.select_by_nickname("zzy");
    user->description("O(∩_∩)O v3");
    ut.update(user);
}
void select_users(zzy_mims::UserTable& ut)
{
    std::vector<std::string> id_list = {"uid1","uid2"};
    auto v = ut.select_multi_users(id_list);
    for(auto user:v)
    std::cout<<user.nickname()<<std::endl;
}
int main(int argc,char* argv[])
{ 
    google::ParseCommandLineFlags(&argc,&argv,true);
    zzy_mims::init_logger(FLAGS_log_mod,FLAGS_log_file,(spdlog::level::level_enum)FLAGS_log_level);
    //关闭brpc的默认日志输出
    // logging::LoggingSettings logset;
    // logset.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    // logging::InitLogging(logset);

    auto db = zzy_mims::ODBFactory::create("root","123456","TESTDB","127.0.0.1","utf8",0,1);
    auto ut = zzy_mims::UserTable(db);
    //insert(ut);
    //update_by_phone(ut);
    //update_by_nickname(ut);
    select_users(ut);
    return 0;
}